package com.dream.inspect.common.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class DateFormatUtil extends DateUtils {
    
    public static String millionSecondsToDateString(long millionSeconds) {  
        Date dat=new Date(millionSeconds);  
        GregorianCalendar gc = new GregorianCalendar();   
        gc.setTime(dat);  
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
        String sb=format.format(gc.getTime()); 
        return sb;
    }
    
    public static Date millionSecondsToDate(long millionSeconds) {
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(millionSeconds); 
        Date date = c.getTime();
        
        return date;
    }
    
    /**
     * 获取当月第一天的时间(date)
     * 
     * @return
     */
    public static Date getFirstDayOfMonthForDate() {
    	Calendar cale = Calendar.getInstance();
        // 获取前月的第一天
        cale = Calendar.getInstance();
        cale.add(Calendar.MONTH, 0);
        cale.set(Calendar.DAY_OF_MONTH, cale.getActualMinimum(Calendar.DAY_OF_MONTH));
        cale.set(Calendar.HOUR_OF_DAY, 0);
        cale.set(Calendar.MILLISECOND, 0);
        cale.set(Calendar.MINUTE, 0);
        cale.set(Calendar.SECOND, 0);
        return cale.getTime();
    }
    
    /**
     * 获取当月第一天的时间(String)
     * 
     * @return
     */
    public static String getFirstDayOfMonthForString() {
    	Calendar cale = Calendar.getInstance();
    	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String firstday = "";
        // 获取前月的第一天
        cale = Calendar.getInstance();
        cale.add(Calendar.MONTH, 0);
        
        cale.set(Calendar.DAY_OF_MONTH, cale.getActualMinimum(Calendar.DAY_OF_MONTH));
        cale.set(Calendar.HOUR_OF_DAY, 0);
        cale.set(Calendar.MILLISECOND, 0);
        cale.set(Calendar.MINUTE, 0);
        cale.set(Calendar.SECOND, 0);
        firstday = format.format(cale.getTime());
        return firstday;
    }
    
    public static void main(String[] args) {
    	Calendar cale = Calendar.getInstance();
    	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String firstday, lastday;
        // 获取前月的第一天
        cale = Calendar.getInstance();
        cale.add(Calendar.MONTH, 0);
        
        cale.set(Calendar.DAY_OF_MONTH, cale.getActualMinimum(Calendar.DAY_OF_MONTH));
        cale.set(Calendar.HOUR_OF_DAY, 0);
        cale.set(Calendar.MILLISECOND, 0);
        cale.set(Calendar.MINUTE, 0);
        cale.set(Calendar.SECOND, 0);
        firstday = format.format(cale.getTime());
//        List<SuperviseImageEntity> siList = new ArrayList<SuperviseImageEntity>();
//        String jasonArray = "[{picName:'test1.jpg',picUrl:'/zp/xx/wt/',picType:'2'},{picName:'test2.jpg',picUrl:'/zp/xx/wt/',picType:'2'}]";
//        
//        siList = JSONObject.parseArray(jasonArray, SuperviseImageEntity.class); 
        
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        long millionSeconds = 1529337600000L;//sdf.parse("20120809030000").getTime();//毫秒
        //System.out.println(millionSeconds);
        Date date= millionSecondsToDate(millionSeconds);
        System.out.println(sdf.format(date));
    }
    
    

}
